﻿var form, $, areaData;
layui.config({
    base: "/scripts/layuiexpand/js/"
}).extend({
    "company": "company"
})
layui.use(['form', 'layer', 'upload', 'laydate', "company"], function () {
    form = layui.form;
    $ = layui.jquery;
    var layer = parent.layer === undefined ? layui.layer : top.layer,
        upload = layui.upload,
        laydate = layui.laydate,
        company = layui.company;
    //日期
    laydate.render({
        elem: '#Bday'
        , type: 'date'
        ////, format: 'yyyy-MM-dd'
        //, value: '2018-08-18'
    });
    //添加验证规则
    form.verify({
        userBirthday: function (value) {
            if (!/^(\d{4})[\u4e00-\u9fa5]|[-\/](\d{1}|0\d{1}|1[0-2])([\u4e00-\u9fa5]|[-\/](\d{1}|0\d{1}|[1-2][0-9]|3[0-1]))*$/.test(value)) {
                return "出生日期格式不正确！";
            }
        }
        , Password: [/(.+){6,12}$/, '密码必须6到12位']
        , ConfirmPassword: function (value) {
            var repassvalue = $('input[name=Password]').val();
            if(value != repassvalue){
                return '两次输入的密码不一致!';
            }
        },
        UniversityID: function (val) {
            if (val == 0||val=="") {
                return "请选择学校";
            }
        },
        CollegeID: function (val) {
            if (val == 0 || val == "") {
                return '学院未选择!';
            }
        }  ,
        GradeID: function (val) {
            if (val == 0 || val == "") {
                return '年级未选择!';
            }
        },
        MajorID: function (val) {
            if (val == 0 || val == "") {
                return '专业未选择!';
            }
        },
        ClassID: function (val) {
            if (val == 0 || val == "") {
                return '班级未选择!';
            }
        }
    })

    //获取所在单位信息
    company.universitys();
   
    //提交个人资料
    form.on("submit(ConfirmRegister)", function (data) {
        //var index = layer.msg('提交中，请稍候', { icon: 16, time: false, shade: 0.8 });
        data.field.ConfirmPassword = $('input[name=ConfirmPassword]').val();
        data.field.UniversityID = $("#UniversityID").val();
        data.field.CollegeID = $("#CollegeID").val();
        data.field.GradeID = $("#GradeID").val();
        data.field.MajorID = $("#MajorID").val();
        data.field.ClassID = $("#ClassID").val();
        $.formSubmit({
            url: "/register/student",
            data: data.field
        });
        //setTimeout(function () {
        //    layer.close(index);
        //    layer.msg("提交成功！" + data.field.classid);
        //}, 2000);
        return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
    })
    //提交教师资料
    form.on("submit(teacherRegister)", function (data) {
        //var index = layer.msg('提交中，请稍候', { icon: 16, time: false, shade: 0.8 });
        data.field.ConfirmPassword = $('input[name=ConfirmPassword]').val();
        data.field.UniversityID = $("#UniversityID").val();
        data.field.CollegeID = $("#CollegeID").val();
        $.formSubmit({
            url: "/register/teacher",
            data: data.field
        });
        return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
    })
    //修改密码
    form.on("submit(changePwd)", function (data) {
        var index = layer.msg('提交中，请稍候', { icon: 16, time: false, shade: 0.8 });
        setTimeout(function () {
            layer.close(index);
            layer.msg("密码修改成功！");
            $(".pwd").val('');
        }, 2000);
        return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
    })
})